﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using LayerData;
using LayerData.Caja;
using LayerEntity.Caja;
using LayerEntity.Sistema;

namespace LayerLogic.Caja
{
    public class LCaja
    {
        #region Variables
        public delegate void AddObject(string msj, EnumOperaciones op, EnumEstadoOperaciones est);
        public event AddObject UpdateList = delegate { };
        readonly IPostgreSqlConnectionInfo connectionInfo;
        readonly DCaja common;
        List<ECaja> bancos = new List<ECaja>();
        #endregion
        #region Constructores
        public LCaja()
        {
            this.InicializaVariables();
            this.connectionInfo = ObjectFactory.CreateConnectionInfo();
            this.common = new DCaja(this.connectionInfo);
        }

        public LCaja(IPostgreSqlConnectionInfo connection)
        {
            this.InicializaVariables();
            this.connectionInfo = connection;
            this.common = new DCaja(connection);
        }

        #endregion
        #region Metodos Privados
        private void InicializaVariables()
        {
        }

        #endregion
        #region MANTENIMIENOS
        public string MantenimientoCajas(ECaja caja, EnumOperaciones op)
        {
            return this.common.MantenimientoCajas(caja, (LayerData.EnumOperaciones)((int)op));
        }
        public object[] AnulaMovCaja(EMovientoCaja Emov, EnumOperaciones op)
        {
            return this.common.AnulaMovCaja(Emov, (LayerData.EnumOperaciones)((int)op));
        }
        #endregion
        #region LISTADO
        public DataTable GetListaTipCaja(ESistema obj)
        {
            return this.common.GetListaTipCaja(obj);
        }

        public DataTable GetListaCaja(ECaja obj)
        {
            return this.common.GetListaCaja(obj);
        }

        public List<ECaja> GetBancos()
        {
            if (this.bancos.Count == 0)
            {
                this.bancos = this.common.GetBancos();
            }
            return this.bancos;
        }

        public ECaja GetBancos(int id) {
            if (this.bancos.Count == 0) {
                bancos = common.GetBancos();
            }
            return bancos.Find(delegate(ECaja c) {
                return c.Id_Caja == id;
            });
        }
        public DataTable getMovPagos(ESistema obj)
        {
            return common.getMovPagos(obj);
        }
        #endregion
    }
}